<?php

namespace app\admin\controller;

use app\admin\controller\Main;
use app\job\DownloadVideo;
use app\job\UploadFileVideo;
use think\Db;
use QRcode;
use think\Queue;

class Index extends Main {

    public function menu() {
        $menu = array(array('title' => '控制台', 'jump' => '/', "icon" => "layui-icon-console"),
            array("icon" => "layui-icon-set", 'title' => '系统设置', 'jump' => 'sysset/basic'),
            array("icon" => "layui-icon-user", 'title' => '用户管理', 'jump' => 'member/index'),
            array("icon" => "layui-icon-face-smile-b", 'title' => '商家管理',
                'jump' => $this->sysset['agent_level'] == '' ? 'merch/index' : 'merch/index1'),
//            array("icon" => "layui-icon-diamond", 'title' => '代理管理',
//                'jump' => $this->sysset['agent_level'] == '' ? 'agent/index' : 'agent/index1'),
            array("icon" => "layui-icon-note", 'title' => '活动管理', 'jump' => 'sale/index'),
            array("icon" => "layui-icon-video", 'title' => '视频记录', 'jump' => 'video/index'),
            array("icon" => "layui-icon-set", 'title' => '管理员设置', 'jump' => 'sysset/adminset'));
        return jsonp($menu);
    }

    public function index() {
//        $res = Queue::push(DownloadVideo::class,['id'=>1],null);
        $platform_name = $this->sysset['basic']['platform_name'];
        $logo = $this->sysset['basic']['logo'];
        $this->view->assign('platform_name', $platform_name);
        $this->view->assign('logo', $logo);
        return $this->view->fetch();
    }

    public function tongji() {
        $data['usernum'] = Db::name('member')->count();
        $data['usernum1'] = Db::name('member')
        ->where('createtime', '>', strtotime("-1 day"))->count();
        $data['merchnum'] = Db::name('member')->where(array('ismerch' => 1))->count();
        $data['merchnum1'] = Db::name('member')->where(array('ismerch' => 1))->where('createtime', '>', strtotime("-1 day"))->count();
        $data['salenum'] = Db::name('sale')->count();
        $data['salenum1'] = Db::name('sale')->where('createtime', '>', strtotime("-1 day"))->count();
        $data['mobileurl'] = $this->request->domain(true);
        $data['apitoken'] = $this->sysset['basic']['apitoken'];
        //$data['auth'] = $this->auth;
        return jsonp($data);
    }

    public function bindmerch() {
        header('content-type: image/png');
        require_once '../extend/qrcode/phpqrcode.php';
        ob_start();
        QRcode::png('https://open.douyin.com/platform/oauth/connect/?client_key='
                . $this->sysset['basic']['client_key']
                . '&response_type=code&scope=user_info,video.create&redirect_uri='
                . urlencode($this->request->domain(true) . '/web/index/bindmerch'), false, 'L', 5, 2);
        $qrcode = ob_get_contents();
        ob_end_clean();
        exit($qrcode);
    }

    public function getopenid() {

        $_GPC = input();
        header('content-type: image/png');
        require_once '../extend/qrcode/phpqrcode.php';
        ob_start();
        QRcode::png('https://open.douyin.com/platform/oauth/connect/?client_key='
                . $this->sysset['basic']['client_key']
                . '&response_type=code&scope=user_info,video.create&redirect_uri='
                . urlencode($this->request->domain(true) . '/web/index/getopenid'), false, 'L', 5, 2);
        $qrcode = ob_get_contents();
        ob_end_clean();
        exit($qrcode);
    }

    public function merchadmin() {
        header('content-type: image/png');
        require_once '../extend/qrcode/phpqrcode.php';
        ob_start();
        QRcode::png($this->request->domain(true) . "/index/merch", false, 'L', 5, 2);
        $qrcode = ob_get_contents();
        ob_end_clean();
        exit($qrcode);
    }

}
